home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / stat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  1.6 KB  |  70 lines

  1. /*
  2.  *        Cross Development System for Atari ST 
  3.  *     Copyright (c) 1988, Memorial University of Newfoundland
  4.  *
  5.  *  The only thing that doesn't get filled in at all is st_ino - it really
  6.  * should be a unique number for each file - any ideas?
  7.  *
  8.  * $Header: stat.c,v 1.2 88/01/29 17:31:52 m68k Exp $
  9.  *
  10.  * $Log:    stat.c,v $
  11.  *
  12.  * 1.2 jrd
  13.  *
  14.  * Revision 1.1  88/01/29  17:31:52  m68k
  15.  * Initial revision
  16.  * 
  17.  */
  18. #include    <types.h>
  19. #include    <stat.h>
  20. #include    <ctype.h>
  21. #include    <errno.h>
  22. #include    <osbind.h>
  23. #include    <string.h>
  24.  
  25.  
  26. int
  27. stat(path, st)
  28.     char        *path;
  29.     struct stat    *st;
  30. {
  31.     int        rval;
  32.     struct _dta    dtabuf;
  33.  
  34.     if (!path) {
  35.         errno = EFAULT;
  36.         return -1;
  37.     }
  38.     if (index(path, '*') || index(path, '?')) {
  39.         errno = EPATH;
  40.         return -1;
  41.     }
  42.     if ((rval = Fsetdta(&dtabuf)) < 0) {
  43.         errno = rval;
  44.         return -1;
  45.     }
  46.     if ((rval = Fsfirst(path, FA_SYSTEM|FA_HIDDEN|FA_DIR)) < 0) {
  47.         errno = rval;
  48.         return -1;
  49.     }
  50.     st->st_mode = dtabuf.dta_attribute & FA_DIR ?  S_IFDIR | 0777
  51.         : (dtabuf.dta_attribute & FA_RDONLY ? S_IFREG | 0555
  52.             : S_IFREG | 0777);
  53.     st->st_ino = 0;        /* should be able to do better then this */
  54.     if (*path && path[1] == ':')
  55.         st->st_dev = islower(*path) ? *path - 'a' : *path - 'A';
  56.     else
  57.         st->st_dev = Dgetdrv();
  58.     st->st_rdev = 0;
  59.     st->st_nlink = 1;
  60.     st->st_uid = 0;
  61.     st->st_gid = 0;
  62.     st->st_size = dtabuf.dta_size;
  63.     st->st_blksize = 1024;
  64.     st->st_blocks = (dtabuf.dta_size + 1023) / 1024;
  65.     st->st_mtime = st->st_ctime = st->st_atime =
  66.         (dtabuf.dta_date << 16) | dtabuf.dta_time;
  67.     st->st_attr = dtabuf.dta_attribute;
  68.     return 0;
  69. }
  70.